$(function() {
	var answerData = parseURL(location.href)
	if(answerData) {
		$('.sheethead').html(answerData.sheetTitleVal)
		$('.subhead').html(answerData.subTitle)
		for(var i = 0; i < answerData.idLength; i++) {
			var _html = '<ul><li>&nbsp;</li><li>0</li><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ul>';
			$(_html).appendTo('.stuIdBox')
		}
		if(answerData.idLength > 14) {
			$('.warningText').css('width', '127mm')
			$('.lostSign').css('height', '36mm')
		}
		for(var i = 0; i < answerData.pageNum; i++) {
			var _html = '';
			if(i == 0) {
				_html = '<li class="pageAct">第' + (i + 1) + '页</li>';
			} else {
				_html = '<li>第' + (i + 1) + '页</li>';
			}
			$(_html).appendTo('.pagebar ul')
		}

	}
	//解析url获取模板数据
	function parseURL(url) {
		if(url.indexOf('?') > -1) {
			var url = url.split("?")[1];
			var para = url.split("&");
			var len = para.length;
			var res = {};
			var arr = [];
			for(var i = 0; i < len; i++) {
				arr = para[i].split("=");
				res[arr[0]] = decodeURI(arr[1]);
			}
			$('.answerSheet').show()
			$('.pagebar').show()
			return res;
		}
	}

	$('.cancel').on('click', function() {
		$('.dialog').fadeOut()

	})
	$('.create').on('click', function() {
		layer.open({
			type: 2,
			content: './tpls/create.html',
			title: '新建答题卡',
			offset: '100',
			area: ['600px', '400px'],
		});
		$('.pagebar').hide()
		$('.answerSheet').hide()
	})
	
	//选择题
	$('.choiceQ').on('click', function() {
		OpenDialog('./tpls/articleEn.html', '英语作文', ['600px', '260px'])
	})
	//判断题
	$('.judgeQ').on('click', function() {
		OpenDialog('./tpls/articleEn.html', '英语作文', ['600px', '260px'])
	})
	//填空题
	$('.fillQ').on('click', function() {
		OpenDialog('./tpls/articleEn.html', '英语作文', ['600px', '260px'])
	})
	//简答题
	$('.shortQ').on('click', function() {
		OpenDialog('./tpls/articleEn.html', '英语作文', ['600px', '260px'])
	})
	//空白样式
	$('.blankStyle').on('click', function() {
		OpenDialog('./tpls/articleEn.html', '英语作文', ['600px', '260px'])
	})
	//英语作文
	$('.articleEn').on('click', function() {
		OpenDialog('./tpls/articleEn.html', '英语作文', ['600px', '260px'])
	})
	//语文作文
	$('.articleZh').on('click', function() {
		OpenDialog('./tpls/articleZh.html', '英语作文', ['600px', '310px'])
	})
	//生成弹框
	function OpenDialog(url, title, area) {
		layer.open({
			type: 2,
			content: url,
			title: title,
			offset: '100',
			area: area,
		})
	}
})